// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   HttpHost.java

package org.quickserver.net.client;

import java.net.URL;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

// Referenced classes of package org.quickserver.net.client:
//            SocketBasedHost

public class HttpHost extends SocketBasedHost
{

    public HttpHost()
    {
        uri = "/";
    }

    public HttpHost(String url)
        throws Exception
    {
        this(new URL(url));
    }

    public void setUrl(URL url)
        throws UnknownHostException
    {
        int port = url.getPort();
        this.url = url;
        if("https".equals(url.getProtocol()))
            setSecure(true);
        setUri(url.getPath());
        if(url.getQuery() != null)
            setUri((new StringBuilder(String.valueOf(getUri()))).append("?").append(url.getQuery()).toString());
        if(port == -1)
            if(isSecure())
                port = 443;
            else
                port = 80;
        setInetSocketAddress(url.getHost(), port);
    }

    public HttpHost(URL url)
        throws UnknownHostException
    {
        uri = "/";
        setUrl(url);
    }

    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        if(getName() != null)
            sb.append(getName());
        sb.append("[");
        if(isSecure())
            sb.append("https://");
        else
            sb.append("http://");
        sb.append(getInetSocketAddress());
        sb.append(getUri());
        sb.append("; Status:");
        sb.append(getStatus());
        sb.append("]");
        return sb.toString();
    }

    public String getUri()
    {
        return uri;
    }

    public void setUri(String uri)
    {
        this.uri = uri;
    }

    public String getHttpStatusCode()
    {
        if(httpStatusCodeList == null)
            return "200";
        if(httpStatusCodeList.size() == 1)
            return (String)httpStatusCodeList.get(0);
        else
            return httpStatusCodeList.toString();
    }

    public void setHttpStatusCode(String httpStatusCode)
    {
        if(httpStatusCode != null)
            if(httpStatusCode.indexOf(",") == -1)
            {
                addHttpStatusCode(httpStatusCode.trim());
            } else
            {
                String array[] = httpStatusCode.split(",");
                for(int i = 0; i < array.length; i++)
                    if(array[i].length() != 0)
                        addHttpStatusCode(array[i].trim());

            }
    }

    public boolean isValidHttpStatusCode(String sc)
    {
        if(httpStatusCodeList != null)
            return httpStatusCodeList.contains(sc);
        else
            return "200".equals(sc);
    }

    public void addHttpStatusCode(String httpStatusCode)
    {
        if(httpStatusCodeList == null)
            httpStatusCodeList = new ArrayList();
        httpStatusCodeList.add(httpStatusCode);
    }

    public URL getUrl()
    {
        return url;
    }

    private String uri;
    private URL url;
    private List httpStatusCodeList;
}
